﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;

namespace IHISCETeim.Web.AgentSys.VipMgr
{
    public partial class VIPExchangePartLookUpList : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
        }
        protected string ItemCode
        {
            get
            {
                return GetRequestValue<string>("ItemCode", "");
            }
        }

        private List<VIPExchangePartLastPriceInfo> _listLast=null;
        protected List<VIPExchangePartLastPriceInfo> listLast
        {
            get {
                if (_listLast==null)
                    _listLast=VIPExchangePartController.GetListLastPrice(base.User.UserId);
                return _listLast;
            }
        }

        protected void DataBind()
        {
            //string showtype = GetRequestValue<string>("itmsGrpCod", "102");
            //DataTable dt = null;

            //if (showtype == "101")
            //{
            //    dt = SBOController.GetYanCaiLiaoOITM(ItemCode, 40);
            //}
            //if (showtype == "102")
            //{
            //    dt = SBOController.GetPaiJinOITMList(ItemCode, 40);
            //}


            ////if (dt == null)
            ////    return ;

            string sqlwhere="";
            if(!string.IsNullOrEmpty(ItemCode))
            {
                sqlwhere=string.Format("ItemCode like '%{0}%' or itemname like '%{0}%'",ItemCode);
            }
            DataTable dt = VIPExchangePartController.GetByWhere(sqlwhere);

            this.rpMenu.DataSource = dt;
            this.rpMenu.DataBind();
        }

        protected string GetPrice(object oldPrice,object ItemCode)
        {
            VIPExchangePartLastPriceInfo obj = listLast.Find(e => e.ItemCode.ToUpper().Trim() == ItemCode.ToString().ToUpper().Trim());
            if (obj == null)
                return oldPrice.ToString();
            else
                return obj.Price.ToString();
        }
    }
}